package manage;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import dataconn.DbWrapper;
import object.Action;
import object.History;

public class HistoryManage{
	public static void AddHistory(int ActionID, String ActionFeild, String OldValue , String NewValue){
		String query="insert into History (ActionID,ActionFeild,OldValue,NewValue) values('"+ActionID+"','"+ActionFeild+"','"+OldValue+"','"+NewValue+"')";
		try{
			  Connection con=DbWrapper.openConnection();
	          Statement stm=con.createStatement();
	          ResultSet rs=stm.executeQuery(query);
	          	          
			    rs.close();
			    stm.close();
			    con.close();
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
		
			     e.printStackTrace();
		}
	}
	public static ArrayList getHistoryList(int AID){
		String query="select * from History where ActionID="+AID;
		ArrayList p1=new ArrayList();
		
		try{
			  Connection conn=DbWrapper.openConnection();
			  Statement stm=conn.createStatement();
	          ResultSet rs=stm.executeQuery(query);
	          
	          while(rs.next()){
	        	  int ActionID= rs.getInt("ActionID");
	        	  int HistoryID=rs.getInt("HistoryID");
	        	  String ActionFeild=rs.getString("ActionFeild");
	        	  String OldValue=rs.getString("OldValue");
	        	  String NewValue=rs.getString("NewValue");
	        	  
	        	  History history=History.getInstance();
	        	  history.setActionID(ActionID);
	        	  history.setHistoryID(HistoryID);
	        	  history.setActionFeild(ActionFeild);
	        	  history.setOldValue(OldValue);
	        	  history.setNewValue(NewValue);
	        	  
	        	  p1.add(history);	          }
	          
	            rs.close();
			    stm.close();
			    conn.close();
			    return p1;
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
		
			     e.printStackTrace();
			     return null;
		}
	}
	
	
}
